<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018-11-27
 * Time: 9:19
 */

namespace app\admin\controller;



header("Access-Control-Allow-Origin:*");

header('Access-Control-Allow-Methods:*');

header('Access-Control-Allow-Headers:*');
use app\common\controller\AdminBase;
use app\common\model\Area;
use app\common\model\File;
use app\common\model\Projectm;
use think\Db;

class Project extends AdminBase
{
//    private $arr = ['doc', 'DOC', 'docx', 'DOCX', 'dotx', 'DOTX', 'dot', 'DOT',  'txt', 'TXT', 'xlsx', 'XLSX', 'xls', 'XLS','rar', 'RAR', 'zip', 'ZIP', 'jar', 'JAR'];
    private $arr = ['doc', 'DOC', 'docx', 'DOCX', 'dotx', 'DOTX', 'dot', 'DOT',  'txt', 'TXT', 'xlsx', 'XLSX', 'xls', 'XLS','rar', 'RAR', 'zip', 'ZIP', 'jar', 'JAR', 'JPG', 'JPEG', 'PNG', 'GIF', 'jpg', 'jpeg', 'png', 'gif'];
    private $size = 5250000;//上传的大小
    /**
     * 证券列表
     */
    public function index($keyword = '', $page = 1)
    {
        $map = [];
        if ($keyword){
                $map= ['p_name' => $keyword];
        }
        $list = Projectm::projectList($map, $page);

        return $this->fetch('index', ['list' => $list, 'keyword' => $keyword]);
    }
    /**
     * 添加证券的页面
     */
    public function add()
    {
        return $this->fetch('add');
    }

    /**
     * 添加证券的方法
     */
    public function addproject()
    {
        if ($this->request->isPost()) {
            $data            = input();
            $validate_result = $this->validate($data, 'Project');
            if ($validate_result !== true) {
                $this->error($validate_result);
            } else {
                if(!array_key_exists("photo",$data)){
                    $this->error('请上传证券头标');
                }
                $id = Projectm::pcAddProject($data);
                if ($id) {
                    $this->success('保存成功');
                } else {
                    $this->error('保存失败');
                }
            }
        }
    }

    /**
     * 修改证券 禁用启用
     */
    public function editstatus($id, $status)
    {
        $res1 = false;
        if ($status == 1) {
            $res1 = Projectm::editProject($id, 2);
        } elseif ($status == 2) {
            $res1 = Projectm::editProject($id, 1);
        } else {
            $this->error('更新失败');
        }
        if (!$res1) {
            $this->error('更新失败');
        }
        $this->success('更新成功');
    }
    /**
     *证券详情
     */
    public function detail($id)
    {
        $detail = Projectm::detail($id);
        return $this->fetch('detail', ['detail' => $detail]);
    }

    /**
     * 修改证券
     */
    public function edit()
    {
        if ($this->request->isPost()) {
            $data            = input();
            $validate_result = $this->validate($data, 'Project');
            if ($validate_result !== true) {
                $this->error($validate_result);
            } else {
                if(!array_key_exists("p_photo",$data)){
                    $this->error('请上传证券头标');
                }
                $id = Projectm::pcEditProject($data);
                if ($id) {
                    $this->success('保存成功');
                } else {
                    $this->error('保存失败');
                }
            }
        }
    }


}